<{extends file="layout.tpl"}>

<{block name=css}>
<style type="text/css">
.m-userDetail-box li:after, .m-userDetail-box2 li:after{ content: ''; display: block; clear: both; }
.m-userDetail-box li, .m-userDetail-box2 li{ line-height: 34px; margin: 10px 0; }
.m-userDetail-box2 li:last-child{ text-align: center; margin-top: 30px; }
.m-userDetail-box .form-control{ width: 260px; }
.m-userDetail-title{ 
	background: #2580A2; 
	color: #fff; 
	font-size: 14px;
	padding-left: 8px;
}
</style>
<{/block}>

<{block name=content}>
<section class="m-panel-box">
	<h4>用户信息详情</h4>
	<div class="m-panel-body">
		<ul class="m-userDetail-box">
			<li class="m-userDetail-title">用户详细信息</li>
			<li>
				<div class="col-md-4">
					用户名
				</div>
				<div class="col-md-8"><span class="m-userDetail-name"></span></div>
			</li>
			<li>
				<div class="col-md-4">用户名*</div>
				<div class="col-md-8"><input type="text" name="username" class="form-control"></div>
			</li>
			<li>
				<div class="col-md-4">真实姓名*</div>
				<div class="col-md-8"><input type="text" name="realname" class="form-control"></div>
			</li>
			<li>
				<div class="col-md-4">联系方式*</div>
				<div class="col-md-8"><input type="text" name="contact_email" class="form-control"></div>
			</li>
			<li class="m-userDetail-title">用户密码</li>
			<li>
				<div class="col-md-4">密码</div>
				<div class="col-md-8"><input type="password" name="password" class="form-control"></div>
			</li>
			<li>
				<div class="col-md-4">密码</div>
				<div class="col-md-8"><input type="password" name="password" class="form-control"></div>
			</li>
			<li class="m-userDetail-title">用户详细信息</li>
			<li>
				<div class="col-md-4">时间</div>
				<div class="col-md-8"><input type="text" name="time" class="form-control" disabled></div>
			</li>
			<li>
				<div class="col-md-4">IP地址</div>
				<div class="col-md-8"><input type="text" name="ipaddress" class="form-control" disabled></div>
			</li>
		</ul>
		<ul class="m-userDetail-box2">
			<li class="m-userDetail-title">用户选项</li>
			<li>
				<div class="col-md-4">option_lang</div>
				<div class="col-md-8 m-userDetail-item1"></div>
			</li>
			<li>
				<div class="col-md-4">option_dateformat</div>
				<div class="col-md-8 m-userDetail-item2"></div>
			</li>
			<li>
				<div class="col-md-4">option_shrink_tableoptions</div>
				<div class="col-md-8"><input type="checkbox" name="option_shrink_tableoptions" value="1">使用默认值时自动隐藏选项表</div>
			</li>
			<li>
				<div class="col-md-4">option_debug</div>
				<div class="col-md-8"><input type="checkbox" name="option_debug" value="1">启用调试日志记录 - 这将影响性能，但会显示所有功能和SQL查询的完整路径</div>
			</li>
			<li>
				<div class="col-md-4">option_concurrent_logins</div>
				<div class="col-md-8"><input type="checkbox" name="option_concurrent_logins" value="1">允许此用户进行多个同时登录</div>
			</li>
			<li>
				<span class="btn btn-md btn-primary m-userDetail-saveBtn">保存设置</span>
			</li>
		</ul>
	</div>
</section>
<{/block}>

<{block name=js}>
<script type="text/javascript">
	$('.m-userDetail-saveBtn').click(function(){
		var allObj = {};
		var userObj = {};
		$('.m-userDetail-box input').each(function(index, data){
			var key = $(data).attr('name');
			if(key == 'username' && $(data).val() == ''){
				userObj[key] = $('.m-userDetail-name').html();
			}else{
				userObj[key] = $(data).val();
			}
		})
		allObj.user = userObj;
		allObj.option_lang = $('.m-userDetail-item1 input:checked').attr('name')|| '';
		allObj.dateformat = $('.m-userDetail-item2 input:checked').val() || '';
		allObj.option_shrink_tableoptions = $('[name="option_shrink_tableoptions"]:checked').val() || 0;
		allObj.option_debug = $('[name="option_debug"]:checked').val() || 0;
		allObj.option_concurrent_logins = $('[name="option_concurrent_logins"]:checked').val() || 0;

		ajaxObj('/UserManage/updateUserInfo', 'post', {data: allObj}, function(obj){
			if(obj.code == 1){
				layer.msg(obj.msg);
			}
		})
	})


	function loadDetail ()
	{	
		var uid = window.location.search.slice(1).split('=')[1];
		ajaxObj('/UserManage/getUserInfo', 'get', {uid}, function(obj){
			console.log(obj);
			$('.m-userDetail-name').html(obj.user.username);
			$('.m-userDetail-box input:not([name="username"])').each(function(index, data){
				var key = $(data).attr('name');
				if(key == 'time'){
					$(data).val(getLocalTime(obj.user[key]))
				}else{
					$(data).val(obj.user[key]);
				}
			})

			var str1 = '';
			obj.optionLang.map(function(data){
				str1 += `<div><input type="radio" name="${data.id}"">${data.label}</div>`;
			})
			$('.m-userDetail-item1').append(str1);

			var str2 = '';
			obj.dateformat.map(function(data){
				str2 += `<div><input type="radio" name="dateformat" value="${data}"/>${data}</div>`
			})
			$('.m-userDetail-item2').append(str2);
		})
	}

	loadDetail();


</script>
<{/block}>